<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>a11y.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_dom_a11y.js.html">a11y.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2007 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Utilities for adding, removing and setting ARIA roles
<a name="line17"></a> * as defined by W3C ARIA Working Draft:
<a name="line18"></a> *     http://www.w3.org/TR/2008/WD-wai-aria-20080806/
<a name="line19"></a> * At this time Firefox 3.0 is the only browser that has good support for ARIA;
<a name="line20"></a> * IE8 (beta) has partial support, while Opera and WebKit implementations
<a name="line21"></a> * are forthcoming. An application could call
<a name="line22"></a> * &lt;code&gt;goog.dom.a11y.setNoBrowserCheck&lt;/code&gt; with true to turn on ARIA
<a name="line23"></a> * support for all browsers.
<a name="line24"></a> *
<a name="line25"></a> */
<a name="line26"></a>goog.provide(&#39;goog.dom.a11y&#39;);
<a name="line27"></a>goog.provide(&#39;goog.dom.a11y.Role&#39;);
<a name="line28"></a>goog.provide(&#39;goog.dom.a11y.State&#39;);
<a name="line29"></a>
<a name="line30"></a>goog.require(&#39;goog.dom&#39;);
<a name="line31"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>/**
<a name="line35"></a> * Enumeration of ARIA states.
<a name="line36"></a> * More will be added later.
<a name="line37"></a> * @enum {string}
<a name="line38"></a> */
<a name="line39"></a>goog.dom.a11y.State = {
<a name="line40"></a>  // ARIA state for setting the currently active descendant of an element.
<a name="line41"></a>  ACTIVEDESCENDANT: &#39;activedescendant&#39;,
<a name="line42"></a>  // ARIA state to specify how input completion is provided.
<a name="line43"></a>  AUTOCOMPLETE: &#39;autocomplete&#39;,
<a name="line44"></a>  // ARIA state for a checked item.
<a name="line45"></a>  CHECKED: &#39;checked&#39;,
<a name="line46"></a>  // ARIA state for a disabled item.
<a name="line47"></a>  DISABLED: &#39;disabled&#39;,
<a name="line48"></a>  // ARIA state for setting whether the element like a tree node is expanded.
<a name="line49"></a>  EXPANDED: &#39;expanded&#39;,
<a name="line50"></a>  // ARIA state for whether the element has a popup
<a name="line51"></a>  HASPOPUP: &#39;haspopup&#39;,
<a name="line52"></a>  // ARIA state for setting the element which labels another element.
<a name="line53"></a>  LABELLEDBY: &#39;labelledby&#39;,
<a name="line54"></a>  // ARIA state for setting the level of an element in the hierarchy
<a name="line55"></a>  LEVEL: &#39;level&#39;,
<a name="line56"></a>  // ARIA state for a pressed item.
<a name="line57"></a>  PRESSED: &#39;pressed&#39;,
<a name="line58"></a>  // ARIA state for setting the currently selected item in the list.
<a name="line59"></a>  SELECTED: &#39;selected&#39;,
<a name="line60"></a>  // ARIA state for slider maximum value.
<a name="line61"></a>  VALUEMAX: &#39;valuemax&#39;,
<a name="line62"></a>  // ARIA state for slider minimum value.
<a name="line63"></a>  VALUEMIN: &#39;valuemin&#39;,
<a name="line64"></a>  // ARIA state for slider active value.
<a name="line65"></a>  VALUENOW: &#39;valuenow&#39;
<a name="line66"></a>};
<a name="line67"></a>
<a name="line68"></a>
<a name="line69"></a>/**
<a name="line70"></a> * Enumeration of ARIA roles.
<a name="line71"></a> * @enum {string}
<a name="line72"></a> */
<a name="line73"></a>goog.dom.a11y.Role = {
<a name="line74"></a>  // ARIA role for a button element.
<a name="line75"></a>  BUTTON: &#39;button&#39;,
<a name="line76"></a>  // ARIA role for a checkbox button element.
<a name="line77"></a>  CHECKBOX: &#39;checkbox&#39;,
<a name="line78"></a>  // ARIA role for a combobox element.
<a name="line79"></a>  COMBOBOX: &#39;combobox&#39;,
<a name="line80"></a>  // ARIA role for a dialog element.
<a name="line81"></a>  DIALOG: &#39;dialog&#39;,
<a name="line82"></a>  // ARIA role for link.
<a name="line83"></a>  LINK: &#39;link&#39;,
<a name="line84"></a>  // ARIA role for listbox.
<a name="line85"></a>  LISTBOX: &#39;listbox&#39;,
<a name="line86"></a>  // ARIA role for popup menu, submenu elements etc.
<a name="line87"></a>  MAIN: &#39;main&#39;,
<a name="line88"></a>  // ARIA role for main content in a document.
<a name="line89"></a>  MENU: &#39;menu&#39;,
<a name="line90"></a>  // ARIA role for a menubar element containing menu elements.
<a name="line91"></a>  MENUBAR: &#39;menubar&#39;,
<a name="line92"></a>  // ARIA role for menu item elements.
<a name="line93"></a>  MENU_ITEM: &#39;menuitem&#39;,
<a name="line94"></a>  // ARIA role for a checkbox box element inside a menu.
<a name="line95"></a>  MENU_ITEM_CHECKBOX: &#39;menuitemcheckbox&#39;,
<a name="line96"></a>  // ARIA role for a radio button element inside a menu.
<a name="line97"></a>  MENU_ITEM_RADIO: &#39;menuitemradio&#39;,
<a name="line98"></a>  // ARIA role for option items, generally used with a parent of listbox.
<a name="line99"></a>  NAVIGATION: &#39;navigation&#39;,
<a name="line100"></a>  // ARIA role for a collection of links suitable for use when navigating
<a name="line101"></a>  // the document or related documents.
<a name="line102"></a>  OPTION: &#39;option&#39;,
<a name="line103"></a>  // ARIA role for a group of elements like a group of radio buttons,
<a name="line104"></a>  // a form, etc.
<a name="line105"></a>  GROUP: &#39;group&#39;,
<a name="line106"></a>  // ARIA role for a slider.
<a name="line107"></a>  SLIDER: &#39;slider&#39;,
<a name="line108"></a>  // ARIA role for a tab button.
<a name="line109"></a>  TAB: &#39;tab&#39;,
<a name="line110"></a>  // ARIA role for a tab bar (i.e. a list of tab buttons).
<a name="line111"></a>  TAB_LIST: &#39;tablist&#39;,
<a name="line112"></a>  // ARIA role for a tab page (i.e. the element holding tab contents).
<a name="line113"></a>  TAB_PANEL: &#39;tabpanel&#39;,
<a name="line114"></a>  // ARIA role for a toolbar element.
<a name="line115"></a>  TOOLBAR: &#39;toolbar&#39;
<a name="line116"></a>};
<a name="line117"></a>
<a name="line118"></a>
<a name="line119"></a>/**
<a name="line120"></a> * Flag for skipping browser check while adding ARIA roles and states.
<a name="line121"></a> * @private
<a name="line122"></a> * @type {boolean}
<a name="line123"></a> */
<a name="line124"></a>goog.dom.a11y.noBrowserCheck_;
<a name="line125"></a>
<a name="line126"></a>
<a name="line127"></a>/**
<a name="line128"></a> * Sets the role of an element.
<a name="line129"></a> * @param {Element} element DOM node to set role of.
<a name="line130"></a> * @param {string} roleName role name(s).
<a name="line131"></a> */
<a name="line132"></a>goog.dom.a11y.setRole = function(element, roleName) {
<a name="line133"></a>  if (goog.userAgent.GECKO || goog.dom.a11y.noBrowserCheck_) {
<a name="line134"></a>    element.setAttribute(&#39;role&#39;, roleName);
<a name="line135"></a>    element.roleName = roleName;
<a name="line136"></a>  }
<a name="line137"></a>};
<a name="line138"></a>
<a name="line139"></a>
<a name="line140"></a>/**
<a name="line141"></a> * Gets role of an element.
<a name="line142"></a> * @param {Element} element DOM node to get role of.
<a name="line143"></a> * @return {string} rolename.
<a name="line144"></a> */
<a name="line145"></a>goog.dom.a11y.getRole = function(element) {
<a name="line146"></a>  return element.roleName || &#39;&#39;;
<a name="line147"></a>};
<a name="line148"></a>
<a name="line149"></a>
<a name="line150"></a>/**
<a name="line151"></a> * Sets the state of an element.
<a name="line152"></a> * @param {Element} element DOM node where we set state.
<a name="line153"></a> * @param {string} state State attribute being set. Automatically adds prefix
<a name="line154"></a> *     &#39;aria-&#39; to the state name.
<a name="line155"></a> * @param {string|boolean|number} value Value for the state attribute.
<a name="line156"></a> */
<a name="line157"></a>goog.dom.a11y.setState = function(element, state, value) {
<a name="line158"></a>  if (goog.userAgent.GECKO || goog.dom.a11y.noBrowserCheck_) {
<a name="line159"></a>    element.setAttribute(&#39;aria-&#39; + state, value);
<a name="line160"></a>  }
<a name="line161"></a>};
<a name="line162"></a>
<a name="line163"></a>
<a name="line164"></a>/**
<a name="line165"></a> * Gets value of specified state property.
<a name="line166"></a> * @param {Element} element DOM node to get state from.
<a name="line167"></a> * @param {string} stateName State name.
<a name="line168"></a> * @return {string} Value of the state attribute.
<a name="line169"></a> */
<a name="line170"></a>goog.dom.a11y.getState = function(element, stateName) {
<a name="line171"></a>  return element.getAttribute(&#39;aria-&#39; + stateName) || &#39;&#39;;
<a name="line172"></a>};
<a name="line173"></a>
<a name="line174"></a>
<a name="line175"></a>/**
<a name="line176"></a> * Getter for noBrowserCheck_ flag.
<a name="line177"></a> * @return {boolean} Value of the noBrowserCheck_ flag.
<a name="line178"></a> */
<a name="line179"></a>goog.dom.a11y.getNoBrowserCheck = function() {
<a name="line180"></a>  return !!goog.dom.a11y.noBrowserCheck_;
<a name="line181"></a>};
<a name="line182"></a>
<a name="line183"></a>
<a name="line184"></a>/**
<a name="line185"></a> * Sets a flag to skip browser check while adding ARIA roles and states.
<a name="line186"></a> * @param {boolean} noBrowserCheck True if no browser check should be performed.
<a name="line187"></a> */
<a name="line188"></a>goog.dom.a11y.setNoBrowserCheck = function(noBrowserCheck) {
<a name="line189"></a>  goog.dom.a11y.noBrowserCheck_ = noBrowserCheck;
<a name="line190"></a>};
<a name="line191"></a>
<a name="line192"></a>
<a name="line193"></a>/**
<a name="line194"></a> * Gets the activedescendant of the given element.
<a name="line195"></a> * @param {Element} element DOM node to get activedescendant from.
<a name="line196"></a> * @return {Element} DOM node of the activedescendant.
<a name="line197"></a> */
<a name="line198"></a>goog.dom.a11y.getActiveDescendant = function(element) {
<a name="line199"></a>  var id = goog.dom.a11y.getState(
<a name="line200"></a>      element, goog.dom.a11y.State.ACTIVEDESCENDANT);
<a name="line201"></a>  return goog.dom.getOwnerDocument(element).getElementById(id);
<a name="line202"></a>};
<a name="line203"></a>
<a name="line204"></a>
<a name="line205"></a>/**
<a name="line206"></a> * Sets the activedescendant value for an element.
<a name="line207"></a> * @param {Element} element DOM node to set activedescendant to.
<a name="line208"></a> * @param {Element} activeElement DOM node being set as activedescendant.
<a name="line209"></a> */
<a name="line210"></a>goog.dom.a11y.setActiveDescendant = function(element, activeElement) {
<a name="line211"></a>  goog.dom.a11y.setState(element, goog.dom.a11y.State.ACTIVEDESCENDANT,
<a name="line212"></a>      activeElement ? activeElement.id : &#39;&#39;);
<a name="line213"></a>};
</pre>


</body>
</html>
